package com.ruoyi.xp.order.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.ruoyi.common.constant.GlobalConstant;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.xp.order.constant.OrderConstant;
import com.ruoyi.xp.order.domain.OrderIncome;
import com.ruoyi.xp.order.dto.OrderInfoDto;
import com.ruoyi.xp.order.mapper.OrderIncomeMapper;
import com.ruoyi.xp.order.mapstruct.OrderMap;
import net.sf.ehcache.search.expression.Or;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.xp.order.mapper.OrderMapper;
import com.ruoyi.xp.order.domain.Order;
import com.ruoyi.xp.order.service.IOrderService;
import com.ruoyi.common.core.text.Convert;

import javax.annotation.Resource;

/**
 * 虾皮订单Service业务层处理
 * 
 * @author chdx
 * @date 2022-12-04
 */
@Service
public class OrderServiceImpl implements IOrderService {
    @Autowired
    private OrderMapper orderMapper;

    /**
     * 查询虾皮订单
     *
     * @param orderId 虾皮订单主键
     * @return 虾皮订单
     */
    @Override
    public Order selectOrderByOrderId(Long orderId) {
        return orderMapper.selectOrderByOrderId(orderId);
    }

    /**
     * 查询虾皮订单列表
     *
     * @param order 虾皮订单
     * @return 虾皮订单
     */
    @Override
    public List<Order> selectOrderList(Order order) {
        return orderMapper.selectOrderList(order);
    }

    /**
     * 新增虾皮订单
     *
     * @param order 虾皮订单
     * @return 结果
     */
    @Override
    public int insertOrder(Order order) {
        order.setCreateTime(DateUtils.getNowDate());
        return orderMapper.insertOrder(order);
    }

    /**
     * 修改虾皮订单
     *
     * @param order 虾皮订单
     * @return 结果
     */
    @Override
    public int updateOrder(Order order) {
        order.setUpdateTime(DateUtils.getNowDate());
        return orderMapper.updateOrder(order);
    }

    /**
     * 批量删除虾皮订单
     *
     * @param orderIds 需要删除的虾皮订单主键
     * @return 结果
     */
    @Override
    public int deleteOrderByOrderIds(String orderIds) {
        return orderMapper.deleteOrderByOrderIds(Convert.toStrArray(orderIds));
    }

    /**
     * 删除虾皮订单信息
     *
     * @param orderId 虾皮订单主键
     * @return 结果
     */
    @Override
    public int deleteOrderByOrderId(Long orderId) {
        return orderMapper.deleteOrderByOrderId(orderId);
    }


    /**
     * 查询订单没有商品信息
     *
     * @return
     */
    @Override
    public List<Order> selectOrderHaveNoItem() {
        return orderMapper.selectOrderHaveNoItem();
    }


    @Override
    public List<Order> selectWarehouseInitOrder() {
        List<String> warehouseOrderStatusList = new ArrayList<>();
        warehouseOrderStatusList.add(OrderConstant.WAREHOUSE_ORDER_STATUS_CANCELLED);
        warehouseOrderStatusList.add(OrderConstant.WAREHOUSE_ORDER_STATUS_UNPAID);
        String warehouseProcessStatus = OrderConstant.WAREHOUSE_PROCESS_STATUS_INIT;
        return orderMapper.selectWarehouseInitOrder(warehouseOrderStatusList, warehouseProcessStatus);
    }

    @Override
    public List<Order> selectWareHouseWaitProcessOrder() {
        return orderMapper.selectWarehouseWaitProcessOrder(OrderConstant.WAREHOUSE_ORDER_STATUS_WAIT_RECEIVER_CONFIRM,
                OrderConstant.WAREHOUSE_PROCESS_STATUS_WAIT_PROCESS);
    }

    @Override
    public List<Order> selectWareHouseWaitPackOrder() {
        return orderMapper.selectWarehouseWaitProcessOrder(OrderConstant.WAREHOUSE_ORDER_STATUS_WAIT_SELLER_SEND,
                OrderConstant.WAREHOUSE_PROCESS_STATUS_WAIT_PACK);
    }

    @Override
    public List<Order> selectOrderWaitToShip() {
        List<String> orderStatusList = new ArrayList<>();
        orderStatusList.add(OrderConstant.ORDER_STATUS_UNPAID);
        orderStatusList.add(OrderConstant.ORDER_STATUS_READY_TO_SHIP);
        orderStatusList.add(OrderConstant.ORDER_STATUS_PROCESSED);
        return orderMapper.selectOrderByOrderStatus(orderStatusList);
    }

    @Override
    public List<Order> selectOrderShipping() {
        List<String> orderStatusList = new ArrayList<>();
        orderStatusList.add(OrderConstant.ORDER_STATUS_SHIPPED);
        orderStatusList.add(OrderConstant.ORDER_STATUS_TO_CONFIRM_RECEIVE);
        orderStatusList.add(OrderConstant.ORDER_STATUS_TO_RETURN);
        orderStatusList.add(OrderConstant.ORDER_STATUS_IN_CANCEL);
        return orderMapper.selectOrderByOrderStatus(orderStatusList);
    }

    /**
     * 查询未有运费的订单
     *
     * @return
     */
    @Override
    public List<Order> selectHaveNoShippingFeeOrder() {
        return orderMapper.selectHaveNoShippingFeeOrder();
    }

}
